/*
 * @lc app=leetcode.cn id=121 lang=javascript
 *
 * [121] 买卖股票的最佳时机
 */

// @lc code=start
/**
 * @param {number[]} prices
 * @return {number}
 */
var maxProfit = function(prices) {
    if(!prices || !prices.length) return 0;
    let len = prices.length;
    let arr = new Array(len).fill(0);
    let min = prices[0];
    for(let i = 1; i<len;i++) {
        let num = prices[i];
        min = Math.min(min,num);
        arr[i] = Math.max(arr[i-1],num-min);
    }
    return arr[len-1];
};
// @lc code=end

